/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.senac.maisconhecimento.servlet;

import br.senac.maisconhecimento.dao.CategoriaDAO;
import br.senac.maisconhecimento.dao.UsuarioDAO;
import br.senac.maisconhecimento.entidade.Categoria;
import br.senac.maisconhecimento.entidade.Usuario;
import br.senac.maisconhecimento.viewdata.ViewDataBase;
import java.io.IOException;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Marcus Lemos
 */
@WebServlet("/Dashboard")
public class DashboardServlet extends BaseServlet {

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        /*
         * UsuarioDAO dao = new UsuarioDAO(); Usuario user =
         * dao.consultarPeloCodigo(1); request.setAttribute("usuarioLogado",
         * user);
         *
         * HttpSession sessionRequest = request.getSession();
         * sessionRequest.setAttribute("usuarioLogado", user);
         */


        HttpSession sessionRequest = request.getSession();
        Object objEmSessao = sessionRequest.getAttribute("usuarioLogado");

        if (objEmSessao == null) {
            RequestDispatcher rd = request.getRequestDispatcher("Login");
            rd.forward(request, response);
        } else {
            request.setAttribute("ViewDataBase", new ViewDataBase(request));

            RequestDispatcher rd = request.getRequestDispatcher("dashboard.jsp");
            rd.forward(request, response);
        }
    }
}
